import {ApiCall, TsrpcError} from "tsrpc";
import {ReqLogin, ResLogin} from "../../shared/protocols/player/PtlLogin";
import {HallManager} from "../../manager/HallManager";


export default async function (call: ApiCall<ReqLogin, ResLogin>) {
    const req = call.req;
    const number = HallManager.instance.addUser(req.username);
    if (number === -1) {
        throw new TsrpcError("用户已存在", {code: 'UserExist'})
    }else {
        call.succ({
            userId: number,
            now: Date.now()
        })
    }
}